package sig.web.struts.converters;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

public class DateConverter extends StrutsTypeConverter {

	private SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");

	@Override
	@SuppressWarnings("unchecked")
	public Object convertFromString(Map context, String[] values, Class toClass) {
		String cadenaFecha = values[0];
		try {
			return format.parse(cadenaFecha);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	@SuppressWarnings("unchecked")
	public String convertToString(Map context, Object fecha) {
		return format.format(fecha);
	}

	
}
